namespace SimpleWebServices.Configuration
{
    using System.Xml.XPath;
    using SimpleWebServices;
    using Xunit;

    public sealed class RepositorySettingFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<RepositorySetting>()
                .DerivesFrom<object>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .XmlRoot("repository")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            RepositorySetting actual = "<repository key='Example' urn='urn://example.com'>Example.Repository</repository>".Deserialize<RepositorySetting>();

            Assert.Equal<string>("Example", actual.Key);
            Assert.Equal<string>("urn://example.com", actual.Urn);
            Assert.Equal<string>("Example.Repository", actual.Value);
        }

        [Fact]
        public void deserializeEmpty()
        {
            RepositorySetting actual = "<repository />".Deserialize<RepositorySetting>();

            Assert.Null(actual.Key);
            Assert.Null(actual.Urn);
            Assert.Null(actual.Value);
        }

        [Fact]
        public void serialize()
        {
            RepositorySetting obj = new RepositorySetting
            {
                Key = "Example",
                Urn = "urn://example.com",
                Value = "Example.Repository"
            };

            XPathNavigator navigator = obj.Serialize().CreateNavigator();

            Assert.True((bool)navigator.Evaluate("'Example.Repository'=/repository[@key='Example'][@urn='urn://example.com']"));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new RepositorySetting());
        }

        [Fact]
        public void prop_Key()
        {
            Assert.True(new PropertyExpectations(typeof(RepositorySetting).GetProperty("Key"))
                .XmlAttribute("key")
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_Urn()
        {
            Assert.True(new PropertyExpectations(typeof(RepositorySetting).GetProperty("Urn"))
                .XmlAttribute("urn")
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_Value()
        {
            Assert.True(new PropertyExpectations(typeof(RepositorySetting).GetProperty("Value"))
                .XmlText()
                .IsAutoProperty<string>()
                .Result);
        }
    }
}